package zhao.tx.eecs.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import zhao.tx.eecs.R;
import zhao.tx.eecs.adapter.DialogAdapter;

/**
 * Created by ishishuji on 14-3-18.
 */
public class MoreDialog extends AlertDialog {

    private TextView hot,now;

    private Handler handler;

    public static final int HOT = 0;

    public static final int NOW = 1;

    private List<String> titles;

    private RelativeLayout dialogGroup;

    private LayoutInflater inflater;

    private ListView listView;

    private DialogAdapter adapter;

    public interface IInformationClieckListener {
        public void onClieck ( View v , int position );
    }

    private IInformationClieckListener listener = new IInformationClieckListener () {
        @Override
        public void onClieck ( View v, int position ) {

            handler.obtainMessage (position).sendToTarget ();
            MoreDialog.this.dismiss ();
        }
    };

    public MoreDialog ( Context context, List< String > titles, Handler handler ) {
        super ( context , R.style.myDialog);
        this.handler = handler;
        this.titles = titles;
        inflater = ( LayoutInflater ) context.getSystemService ( Context.LAYOUT_INFLATER_SERVICE );
    }

    @Override
    protected void onCreate ( Bundle savedInstanceState ) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.type_dialog );

        Window win = this.getWindow();

        win.setGravity ( Gravity.RIGHT | Gravity.TOP );

        dialogGroup = ( RelativeLayout ) findViewById ( R.id.dialog_group );

        listView = ( ListView ) findViewById ( R.id.dialogList );

        adapter = new DialogAdapter ( getContext () , titles );

        adapter.setOnInformationClieckListener ( listener );

        listView.setAdapter ( adapter );

        this.setCanceledOnTouchOutside(true);

    }

    public void updateData ( ) {
        adapter.notifyDataSetChanged ();
    }


}
